<template>
  <!-- 顾客登录 -->
  <div>
    <div class="container">
      <div class="item12">
        <div class="item1">
          <mymenu></mymenu>
        </div>
        <div class="item2">
          <van-field v-model="nickname" label="昵称" placeholder="昵称" />
          <van-field v-model="mobile" label="手机号" placeholder="手机号" />
          <van-field
            v-model="password"
            type="password"
            label="密码"
            placeholder="请输入密码"
          />
          <br /><br />

          <van-button type="primary" @click="submit">登录</van-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      nickname: "",
      mobile: "",
      password: "",
    };
  },
  methods: {
    submit: function () {
      if (this.nickname == "") {
        this.$toast.fail("昵称不能为空");
        return false;
      }
      if (this.mobile == "") {
        this.$toast.fail("手机号不能为空");
        return false;
      }
      if (this.password == "") {
        this.$toast.fail("密码不能为空");
        return false;
      }
      this.myaxios(this.weburl + "user/login/", "post", {
        nickname: this.nickname,
        mobile: this.mobile,
        password: this.password,
      }).then((data) => {
        console.log("data", data);
        if (data.code == 200) {
          this.$toast.success(data.msg);

          // 登陆成功存储用户信息
          localStorage.setItem("token", data.token);
          localStorage.setItem("id", data.data.id);
          localStorage.setItem("user_type", data.data.user_type);
          if (data.data.user_type == null) {
            // 登陆成功跳转个人信息
            this.$router.push({
              path: "/index/usersinfo",
              query: { id: data.data.id },
            });
          }else{
            this.$router.push({
              path: "/shopsindex/shopsinfo",
              query: { id: data.data.id },
            });
          }
        } else {
          this.$toast.fail(data.msg);
        }
      });
    },
  },
  created() {},
};
</script>

<style scoped>
</style>